<?php /*a:3:{s:69:"D:\phpstudy_pro\WWW\www.system.loc\app\admin\template\menu\index.html";i:1597971115;s:70:"D:\phpstudy_pro\WWW\www.system.loc\app\admin\template\common\head.html";i:1597971115;s:70:"D:\phpstudy_pro\WWW\www.system.loc\app\admin\template\common\foot.html";i:1597971115;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>vaeThink</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/admin_static/lib/layui/css/layui.css"  media="all">
</head>
<body>
<div class="layui-btn-container">
  <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-demo="add">添加菜单</button>
</div>
 
<div id="test12" class="demo-tree-more"></div>
        
<script src="/static/admin_static/lib/layui/layui.js" charset="utf-8"></script>


<script>
layui.config({
    base: '/static/admin_static/module/'
}).use(['tree', 'util', 'vae'], function(){
  var tree = layui.tree
  ,layer = layui.layer
  ,util = layui.util
  ,$ = layui.$
  ,vae = layui.vae;

  let data;
  vae.ajax({
    url:"<?php echo url('admin/menu/index'); ?>",
    async:false,
    success:function(res){
      if(res.code == 200){
        data = res.data;
      }else{
        layer.msg(res.msg);
        return false;
      }
    }
  })

  //基本演示
  tree.render({
    elem: '#test12'
    ,data: data
    ,edit: ['del']
    ,id: 'demoId1'
    ,onlyIconControl: true
    ,click: function(obj){
      //修改
      var data = obj.data;  //获取当前点击的节点数据
      vae.open({
        href: "<?php echo url('admin/menu/edit'); ?>?id="+data.id,
        title: '修改菜单'+data.id,
        end: function(res) {
          tree.reload('demoId1', {
            
          });
        }
      });
    }
    ,operate: function(obj){
      var type = obj.type; //得到操作类型：add、edit、del
      var data = obj.data; //得到当前节点的数据
      var elem = obj.elem; //得到当前节点元素
      
      //Ajax 操作
      var id = data.id; //得到节点索引
      if(type === 'del'){ //删除节点
        vae.ajax({
          url:"<?php echo url('admin/menu/delete'); ?>",
          data:{id:id},
          success:function(res){
            layer.msg(res.msg);
            if(res.code !== 200) {
              return false;
            }
          }
        })
        return false;
      }
    }
  });
  
  //按钮事件
  util.event('lay-demo', {
    add: function(){
      vae.open({
        href: "<?php echo url('admin/menu/add'); ?>",
        title: '添加菜单',
        end: function(res) {
          tree.reload('demoId1', {
            
          });
        }
      });
    }
    ,reload: function(){
      //重载实例
      tree.reload('demoId1', {
        
      });
      
    }
  });
});
</script>

</body>
</html>